package cn.tedu.batch.transformation

import org.apache.flink.api.scala.ExecutionEnvironment

/**
 * @author Amos
 * @date 2022/5/19
 */

// reducegroup算子
object BatchReduceGroupDemo {
  def main(args: Array[String]): Unit = {
    val env = ExecutionEnvironment.getExecutionEnvironment

    import org.apache.flink.api.scala._
    val source: DataSet[(String, Int)] = env.fromElements(("java", 1), ("java", 1), ("scala", 2), ("scala", 1), ("java", 2))

    val result = source.groupBy(0).reduceGroup(iter => iter.reduce((x,y) => {(x._1,x._2+y._2)}))
    result.print()


  }

}
